package com.x.erp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.erp.model.ImageView;
import com.x.erp.rpc.ImageViewRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 图片场景信息
 */
@RestController
@RequestMapping("/imageView")
public class ImageViewController extends BaseController{

	@Reference
	private ImageViewRpcService imageViewRpcService;//图片场景信息服务

	/**
	 * 查询图片场景信息列表
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getImageViewList", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getImageViewList(ImageView imageView) {

		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", imageViewRpcService.selectImageViewList(imageView));
	}

	/**
	 * 查询图片场景信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getImageViewListById", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getImageViewListById(ImageView imageView) {
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", imageViewRpcService.selectImageViewListById(imageView));
	}

	/**
	 * 查询图片场景信息数量
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getImageViewNum", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getImageViewNum(ImageView imageView) {
		Map<String, Object> res = new HashMap<>();
		res.put("total", imageViewRpcService.selectImageViewNum(imageView));
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", res);
	}

	/**
	 * 新增图片场景信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/insertImageView", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel insertImageView(ImageView imageView, String[] imageViewTypeList) {
		if(imageView.getImageViewId() == null){
			return new ResultModel(ResultCode.RESULT_FAIL, "图片场景ID不能为空！");
		}
		if(StringUtils.isEmpty(imageView.getImageViewName())){
			return new ResultModel(ResultCode.RESULT_FAIL, "图片场景名称不能为空！");
		}
		if(imageViewTypeList == null || imageViewTypeList.length == 0){
			return new ResultModel(ResultCode.RESULT_FAIL, "请选择场景图片名称！");
		}
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", imageViewRpcService.insertImageView(imageView, imageViewTypeList));
	}

	/**
	 * 修改图片场景信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/updateImageView", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel updateImageView(ImageView imageView, String[] imageViewTypeList) {
		if(imageView.getImageViewId() == null){
			return new ResultModel(ResultCode.RESULT_FAIL, "图片场景ID不能为空！");
		}
		if(StringUtils.isEmpty(imageView.getImageViewName())){
			return new ResultModel(ResultCode.RESULT_FAIL, "图片场景名称不能为空！");
		}
		if(imageViewTypeList == null || imageViewTypeList.length == 0){
			return new ResultModel(ResultCode.RESULT_FAIL, "请选择场景图片名称！");
		}
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", imageViewRpcService.updateImageView(imageView, imageViewTypeList));
	}

}
